package cn.bugDance.test.domain.activity;

import cn.bugDance.domain.activity.event.ActivitySkuStockOverEvent;
import cn.bugDance.domain.activity.model.entity.*;
import cn.bugDance.domain.activity.model.valobj.TradeTypeVO;
import cn.bugDance.domain.activity.service.IRaffleActivityPartakeService;
import cn.bugDance.domain.activity.service.IRaffleActivityService;
import cn.bugDance.domain.activity.service.armory.IRaffleActivityArmory;
import cn.bugDance.domain.activity.service.quota.IRaffleActivityQuotaService;
import cn.bugDance.infrastructure.event.EventPublisher;
import cn.bugstack.middleware.db.router.strategy.IDBRouterStrategy;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.TestTemplate;
import org.junit.platform.commons.util.StringUtils;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.concurrent.CountDownLatch;

@SpringBootTest
@RunWith(SpringRunner.class)
@Slf4j
public class ActivityTest {

    @Resource
    private IRaffleActivityArmory raffleActivityArmory;
    @Resource
    private IRaffleActivityService raffleActivityService;
    @Resource
    private IRaffleActivityPartakeService raffleActivityPartakeService;
    @Resource
    private IRaffleActivityQuotaService raffleActivityQuotaService;
    @Resource
    private EventPublisher eventPublisher;





    @Test
    public void test() throws InterruptedException {
        ActivitySkuStockOverEvent event = ActivitySkuStockOverEvent.create(1001L);
        eventPublisher.publish("skuStockOverTopic", event);
        new CountDownLatch(1).await();
    }

    @Test
    public void test_partake(){
        PartakeActivityFactorEntity partakeActivityFactorEntity = new PartakeActivityFactorEntity();
        partakeActivityFactorEntity.setActivityId(100301L);
        partakeActivityFactorEntity.setUserId("yangxiaocan");

        ActivityPartakeOrderEntity activityPartakeOrderEntity = raffleActivityPartakeService.partakeActivity(partakeActivityFactorEntity);

        log.info("结果: {}", JSON.toJSONString(activityPartakeOrderEntity));
    }


    @Test
    public void test3() throws InterruptedException {
        ActivityShopCartEntity activityShopCartEntity = new ActivityShopCartEntity();
        activityShopCartEntity.setBizId(RandomStringUtils.randomNumeric(12));
        activityShopCartEntity.setUserId("yangxiaocan");
        activityShopCartEntity.setSku(1002L);
        ActivitySkuOrderEntity activitySkuOrder = raffleActivityService.createActivitySkuOrder(activityShopCartEntity);

        //PartakeActivityFactorEntity partakeActivityFactorEntity = new PartakeActivityFactorEntity();
        //partakeActivityFactorEntity.setActivityId(100301L);
        //partakeActivityFactorEntity.setUserId("yangxiaocan");

        //ActivityPartakeOrderEntity activityPartakeOrderEntity = raffleActivityPartakeService.partakeActivity(partakeActivityFactorEntity);
        log.info("结果位: {}", JSON.toJSONString(activitySkuOrder));
        new CountDownLatch(1).await();
    }

    @Test
    public void test_credit_sku() throws InterruptedException {
        ActivityShopCartEntity activityShopCartEntity = new ActivityShopCartEntity();
        activityShopCartEntity.setUserId("yangxiaocan");
        activityShopCartEntity.setSku(1003L);
        activityShopCartEntity.setBizId(RandomStringUtils.randomNumeric(12));
        activityShopCartEntity.setTradeType(TradeTypeVO.credit_pay);

        ActivitySkuOrderEntity activitySkuOrderEntity = raffleActivityService.createActivitySkuOrder(activityShopCartEntity);
        new CountDownLatch(1).await();
    }

    @Test
    public void test_updateOrder(){
        DeliverOrderEntity deliverOrderEntity = new DeliverOrderEntity();
        deliverOrderEntity.setUserId("yangxiaocan");
        deliverOrderEntity.setOutBusinessNo("141969004315");

        raffleActivityQuotaService.updateCreditPayOrder(deliverOrderEntity);
    }
}
